<template>
  <div class="activitycontent">
    <!--活动详情-->
    <div class="page-container">
      <div class="container">
        <div class="row">
          <!--左边-->
          <div class="span8 page-content">
            <el-page-header @back="$router.back(-1)" content="活动详情"></el-page-header>
            <article class="type-post format-standard hentry clearfix">
              <h3>{{content.activity_title}}</h3>
              <div>
                <div class="show_unit ativity">
                  <a class="iconfont ic">&#xe622;</a>
                  <a class="tagname">活动名称:</a>
                  {{content.activity_title}}
                </div>
                <el-popover placement="left" width="400" trigger="hover">
                  <span>
                    <li class="comment even thread-odd thread-alt depth-1" id="li-comment-4">
                      <article id="comment-4">
                        <img
                          :src="content.avatar"
                          class="avatar touxiang avatar-60 photo"
                          height="60"
                          width="60"
                        />

                        <div class="comment-meta">
                          <h5 class="author">{{content.nickname}}</h5>
                          <p class="date" v-if="content.realstate==3">认证用户</p>
                          <p class="date" v-else>未认证用户</p>
                        </div>
                      </article>
                    </li>
                    <div class="xinxi">
                      <p style="color: #000;">账号：</p>
                      <p>{{content.username}}</p>
                    </div>
                    <div class="xinxi">
                      <p style="color: #000;">邮箱：</p>
                      <p>{{content.mail}}</p>
                    </div>
                    <div class="xinxi">
                      <p style="color: #000;">QQ：</p>
                      <p>{{content.qq}}</p>
                    </div>
                    <div class="xinxi">
                      <p style="color: #000;">个人简介：</p>
                      <p>{{content.synopsis}}</p>
                    </div>
                     <el-button
                       @click="jubao(content.username)"
                       style="margin:10px 150px"
                       type="danger"
                       plain
                     >举报</el-button>
                  </span>
                  <div slot="reference" class="show_unit fl ativity">
                    <a class="iconfont ic">&#xe66a;</a>
                    <a class="tagname">发起者:</a>
                    {{content.nickname}}
                  </div>
                </el-popover>
                <div class="show_unit fl ativity" style="width: 80%;">
                  <a class="iconfont ic">&#xe62a;</a>
                  <a class="tagname">活动时间:</a>
                  {{content.activity_statetime|dataFormat}}——{{content.activity_endtime|dataFormat}}
                </div>
                <div class="show_unit fl ativity">
                  <a class="iconfont ic">&#xe62a;</a>
                  <a class="tagname">活动人数:</a>
                  {{content.activity_num}}
                </div>
                <div class="show_unit fl ativity">
                  <a class="iconfont ic">&#xe62a;</a>
                  <a class="tagname">活动地点:</a>
                  {{content.activity_locale}}
                </div>
                <div style="clear:both"></div>
                <!--占位-->
              </div>
              <h3>活动描述</h3>
              <pre v-html="content.activity_content"></pre>
            </article>
            <el-button
              type="primary"
              @click="setJoin"
              style="width:80px;margin:0 auto;display:block;"
            >参加
            </el-button>
            <div class="block">
              <h3>活动公告</h3>
              <el-timeline>
                <el-timeline-item
                  v-for="(item,id) in announcementlist"
                  :key="id"
                  :timestamp="item.announcement_createtime | dataFormat"
                  placement="top"
                >
                  <el-card>
                    <h4>{{item.announcement_name}}</h4>
                    <p>{{item.announcement_content}}</p>
                  </el-card>
                </el-timeline-item>
              </el-timeline>
            </div>
            <div class="like-btn">
            </div>
            <comment/>
          </div>
          <!--右边-->
          <aside class="span4 page-sidebar">
            <carousel/>
            <activity/>
          </aside>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import comment from '../../components/comment'
import carousel from '../../components/carousel'
import activity from '../../components/activity'

import { mapActions, mapState } from 'vuex'

export default {
  name: 'activitycontent',
  components: { comment, carousel, activity },
  data () {
    return {
      data: {
        type: '', // 类型
        name: '', //  名称
        describe: '', //  描述
        content_id: '',
        activity_title: '',
        to_userid: ''
      },
      dialogFormVisible: false, // 弹框相关
      content: {},
      announcementlist: {}
    }
  },
  props: {
    id: {}
  },
  computed: {
    ...mapState({
      contentuserid: state => state.contentuserid,
      commentnum: state => state.commentnum,
      userinfo: state => state.user.userinfo
    })
  },
  methods: {
    ...mapActions(['setcontentid', 'setcontentinfo']),
    jubao (username) {
      const url = escape(window.location.href)
      this.$router.push({ path: '/report', query: { user: username, url: url } })
    },
    async getActivityContent () {
      const data = {
        id: this.id
      }
      const result = await this.$axios.post('/web/getactivitycontent', this.qs.stringify(data))
      if (result.data.state.type === 'SUCCESS') {
        this.content = result.data.data
        this.setcontentinfo({
          contentname: result.data.data.activity_title,
          contentuserid: result.data.data.user_id
        })
      }
    },
    async setJoin () {
      if (!this.userinfo.avatar) {
        this.$message.error('请先登录')
        return
      } else if (this.userinfo.realstate !== 3) {
        this.$message.error('请先进行学生认证')
        return
      }
      this.data.type = this.$route.name // 类型
      this.data.content_name = this.content.activity_title
      this.data.to_userid = this.contentuserid
      this.data.content_id = this.content.activity_id
      const result = await this.$axios.post('/web/setjoin', this.qs.stringify(this.data))
      if (result.data.state.type === 'SUCCESS') {
        this.$message.success('参加成功')
      } else {
        this.$message.error('你已经报名参加了本项目')
      }
    },
    // 获取公告列表
    async getAnnouncementList () {
      const result = await this.$axios.post('/admin/announcementlist', this.qs.stringify({ content_id: this.id }))
      console.log(result)
      if (result.data.state.type === 'SUCCESS') {
        this.announcementlist = result.data.data
        console.log(111)
      }
    }
  },
  watch: {
    id: {
      handler (newVal) {
        this.getActivityContent()
        this.getAnnouncementList()
        this.setcontentid(this.id)
      },
      deep: true,
      immediate: true
    }
  },
  created () {
    this.getAnnouncementList()
    this.setcontentid(this.id)
  }
}
</script>

<style scoped>
  .activitycontent {
    min-height: 200px;
  }

  .tagname {
    margin-right: 16px;
    font-size: 18px;
  }

  .show_unit {
    margin-bottom: 10px;
    height: 50px;
    line-height: 50px;
  }

  .ic {
    color: #409eff;
    margin-right: 30px;
    font-size: 30px;
  }
</style>
